#pragma once
#include "afxwin.h"
#include "definitions.h"
#include "CheckFitness.h"
#include "ScriptParser.h"

// CMainDlg dialog

namespace SNU
{
	class CMainDlg : public CDialogEx
	{
		DECLARE_DYNAMIC(CMainDlg)

	public:
		CMainDlg(const CString& strInitPath, CWnd* pParent = NULL);   // standard constructor
		virtual ~CMainDlg();

	// Dialog Data
		enum { IDD = IDD_BILL_VIEWER };

	protected:
		virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

		DECLARE_MESSAGE_MAP()

	private:
		enum EItemState
		{
			ITEMSTATE_NONE,
			ITEMSTATE_GBCPARSED,
			ITEMSTATE_FITNESS,
			ITEMSTATE_UNFITNESS,
			ITEMSTATE_PARSEERROR,
			ITEMSTATE_DETECTCORNER_FAILED,
		};
		class CInnerListData
		{
		public:
			CInnerListData();
			CInnerListData(const CString& strInputPath, int nBillType, int nBillDirection);
			~CInnerListData();
			bool Parse();

			void SetState(EItemState eState) {m_eState = eState;}
			EItemState GetState() const {return m_eState;}
			CString GetPath() const {return m_strFilePath;}
			char** GetImageArray() {return m_ppImageArray;}
			int GetBillDirection() const {return m_nBillDirection;}
			int GetBillType() const {return m_nBillType;}

		private:

			EItemState m_eState;
			CString m_strFilePath;
			int m_nBillType;
			int m_nBillDirection;
			char** m_ppImageArray;
		};
		enum
		{
			NUM_OF_VIEWS	= 8,
			VIEWMODE_1		= 0x00000001,
			VIEWMODE_2		= 0x00000002,
			VIEWMODE_3		= 0x00000004,
			VIEWMODE_4		= 0x00000008,
			VIEWMODE_5		= 0x00000010,
			VIEWMODE_6		= 0x00000020,
			VIEWMODE_7		= 0x00000040,
			VIEWMODE_8		= 0x00000080,
			VIEWMODE_9		= 0x00000100,
		};
		enum
		{
			MASK_CHECK_ALGORITHM_SOIL		= 0x00000001,
			MASK_CHECK_ALGORITHM_STAIN		= 0x00000002,
			MASK_CHECK_ALGORITHM_GRAFFITI	= 0x00000004,
			MASK_CHECK_ALGORITHM_DEINKED	= 0x00000008,
			MASK_CHECK_ALGORITHM_TEAR		= 0x00000010,
			MASK_CHECK_ALGORITHM_HOLE		= 0x00000020,
			MASK_CHECK_ALGORITHM_MULTILATION= 0x00000040,
			MASK_CHECK_ALGORITHM_REPAIR		= 0x00000080,
			MASK_CHECK_ALGORITHM_CRUMPLES	= 0x00000100,
			MASK_CHECK_ALGORITHM_LIMPNESS	= 0x00000200,
			MASK_CHECK_ALGORITHM_FOLD		= 0x00000400,
			MASK_CHECK_ALGORITHM_FOLDEDCORNER= 0x00000800
		};
		enum
		{
			CHECK_ALGORITHM_SOIL	= 0,
			CHECK_ALGORITHM_STAIN,
			CHECK_ALGORITHM_GRAFFITI,
			CHECK_ALGORITHM_DEINKED,
			CHECK_ALGORITHM_TEAR,
			CHECK_ALGORITHM_HOLE,
			CHECK_ALGORITHM_MULTILATION,
			CHECK_ALGORITHM_REPAIR,
			CHECK_ALGORITHM_CRUMPLES,
			CHECK_ALGORITHM_LIMPNESS,
			CHECK_ALGORITHM_FOLD,
			CHECK_ALGORITHM_FOLDEDCORNER,
			NUMBER_OF_ALGORITHMS
		};

		CString m_astrViewModeNames[9];
		CListCtrl m_listctrlFiles;
		CString m_strCurFilePath;
		int m_nNumberOfTest;
		CString m_strElapsedTime;

		CComboBox m_cmbBilltype;
		CBitmap m_bitmapView, *m_pbitmapOld;
		CDC m_dcMem;
	
		int m_nViewHeight;
		char** m_ppImageArrays;

		int m_anAlgorithmResource[12];
		PFUNC_FITCHECK_ALGORITHM m_pfuncAlgorithms[12];

		int	GetViewMode();
		int GetCheckAlgorithmMode();
		void UpdateView(const CString& strFilepath);
		void AddFilesToList(const CString& strPath, int nBillType, int nBillDirection);
		void ClearList();
		void ParseTestScript(const CString& strPath);

		afx_msg void OnBnClickedButtonBrowsefile();
		afx_msg void OnBnClickedButtonBrowsefolder();
		afx_msg void OnBnClickedButtonOpen();

	public:
		CScrollBar m_scrollbarView;
		virtual BOOL OnInitDialog();
		afx_msg void OnPaint();

		afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
		afx_msg void OnDestroy();
		afx_msg void OnNMCustomdrawListFiles(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnLvnItemchangedListFiles(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnBnClickedCheckView();
		afx_msg void OnCbnSelchangeComboBilltype();
		CComboBox m_cmbBillDirection;
	};
};